package com.working.libbase.base

import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.databinding.ViewDataBinding
import androidx.fragment.app.Fragment
import com.working.libcommon.exts.cast
import com.working.libcommon.exts.statusBarColor
import com.working.libcommon.util.LogUtils
import com.working.libcommon.util.loge

abstract class BaseFragment : Fragment() {


    private val className = this.javaClass.simpleName
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        LogUtils.e("$className onCreate")
    }

    override fun onDestroy() {
        super.onDestroy()
        LogUtils.e("$className onDestroy")
    }

    override fun onDestroyView() {
        super.onDestroyView()
        LogUtils.e("$className onDestroyView")
    }

    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        LogUtils.e("$className onCreateView")
        return super.onCreateView(inflater, container, savedInstanceState)
    }

    override fun onResume() {
        super.onResume()
        LogUtils.e("$className onResume")
    }

    override fun onStart() {
        LogUtils.e("$className onStart")
        super.onStart()
    }

    override fun onStop() {
        LogUtils.e("$className onStop")
        super.onStop()
    }

    protected inline fun <reified T : ViewDataBinding> binding(
        inflater: LayoutInflater,
        @LayoutRes resId: Int,
        container: ViewGroup?
    ): T = DataBindingUtil.inflate(inflater, resId, container, false)

    fun immerseColor(colorInt: Int) {
        activity?.cast<AppCompatActivity>()?.supportActionBar?.setBackgroundDrawable(
            ColorDrawable(
                colorInt
            )
        )
        activity?.statusBarColor(colorInt)
    }


}